package com.hll.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hll.erp.dao.ProductDao;
import com.hll.erp.entity.Product;
import com.hll.erp.service.ProductService;
import org.springframework.stereotype.Service;

/**
 * (Product)表服务实现类
 *
 * @author makejava
 * @since 2021-07-04 15:17:56
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductDao, Product> implements ProductService {
  @Override
  public Page<Product> getProducts(
      Integer current, Integer pageSize, String name, Integer category) {
    Page<Product> page = new Page<>(current, pageSize);
    QueryWrapper<Product> wrapper = new QueryWrapper<>();
    if (name != null) wrapper.like("pname", name);
    if (category != null) wrapper.eq("category", category);
    page = this.page(page, wrapper);
    return page;
  }

  @Override
  public Product getProductByName(String name) {
    return this.getOne(new QueryWrapper<Product>().eq("pname", name));
  }
}
